/**
 * @param {character[][]} board
 * @return {void} Do not return anything, modify board in-place instead.
 */
// 深度优先遍历?
var solve = function (board) {
    const m = board.length, n = board[0].length
    const directions = [{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 0, y: -1 }, { x: 0, y: 1 }]
    const dfs = function(i, j) {
        board[i][j] = "-"
        for(let k = 0; k < 4; k++) {
            let x = i + directions[k].x
            let y = j + directions[k].y
            if(x >= 0 && x < m && y >= 0 && y < n && board[x][y] === "O") {
                dfs(x, y)
            }
        }
    }
    for(let i = 0; i < m; i++) {
        if(board[i][0] === "O") {
            dfs(i, 0)
        }
        if(board[i][n - 1] === "O") {
            dfs(i, n - 1)
        }
    }
    for(let j = 0; j < n; j++) {
        if(board[0][j] === "O") {
            dfs(0, j)
        }
        if(board[m - 1][j] === "O") {
            dfs(m - 1, j)
        }
    }
    for(let i = 0; i < m; i++) {
        for(let j = 0; j < n; j++) {
            if(board[i][j] === "-") board[i][j] = "O"
            else if(board[i][j] === "O") board[i][j] = "X"
        }
    }
};
// function invalid(x, y) {
//     // 在边界上，且为O无效
//     if ((x == 0 || x == m - 1 || y == 0 || y == n - 1) && board[x][y] === "O") return true
//     return false
// }
// function canDfs(x, y) {
//     if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] === 'O' && !haveVisited[x][y]) return true
//     return false
// }
solve([["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]])